package com.ckk.cloud.provider.payment8001.controller;


import com.ckk.apicommoncloud.entity.CommonResult;
import com.ckk.apicommoncloud.entity.Payment;
import com.ckk.cloud.provider.payment8001.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author 陈昆昆
 * @version 1.0
 * @date 2020/6/15 15:14
 */
@RestController
@Slf4j
public class PaymentCaontroller
{
    @Autowired
    private PaymentService paymentServiceImpl;
    @Value("${server.port}")
    private String serverPort;

    @PostMapping("payment/create")
    public CommonResult create(@RequestBody Payment payment)
    {
        log.info("新增开始");
        int result = paymentServiceImpl.create(payment);
        if (result>0) {
            log.info("create方法新增结果" + result);
            return new CommonResult(200,"新增成功",result);
        }
        log.info("create方法新增结果"+result);
        return new CommonResult(444,"新增失败",null);
    }

    @GetMapping(value="/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
        Payment payment = paymentServiceImpl.getPaymentById(id);
        log.info("****查询结果:" + payment);
        if(payment != null){
            return  new CommonResult(200,"查询成功,serverPort: "+serverPort,payment);
        } else {
            return new CommonResult(444,"没有对应记录，查询ID: " + id,null);
        }
    }
    @GetMapping(value = "payment/get/timeout")
    public String out(){
        return serverPort;
    }
}
